import React from 'react';
import TabNavigator from 'react-native-tab-navigator';

export default class TabBar extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      selectedTab: props.selectedTab
    };
  }

  render() {
    return (
      <TabNavigator>
        {this.props.tabBarConfig.map(item => (
          <TabNavigator.Item
            key={item.title}
            selected={this.state.selectedTab === item.selected}
            title={item.title}
            titleStyle={item.titleStyle}
            selectedTitleStyle={item.selectedTitleStyle}
            renderIcon={() => item.renderIcon}
            renderSelectedIcon={() => item.renderSelectedIcon}
            onPress={() => item.clicked(this)}>
            {item.content}
          </TabNavigator.Item>
        ))}
      </TabNavigator>
    );
  }
}
